package com.cn.goodsadmin.requestinfo;

import com.alibaba.fastjson.JSONObject;
import com.cn.goodsadmin.common.frame.BaseHttpNetWork;
import com.cn.goodsadmin.common.frame.RequestInfo;
import com.cn.goodsadmin.util.TimeUtil;

import java.util.Date;

public class OrderStatusRequest extends BaseHttpNetWork {

    public OrderStatusRequest(RequestInfo info) {
        super(info);
    }

    @Override
    public void setHeader() {

    }

    @Override
    public byte[] setBody(RequestInfo info) {
        OrderStatusRequestInfo orderStatusRequestInfo = (OrderStatusRequestInfo) info;
        try {
            JSONObject object = new JSONObject();
            object.put("touser", orderStatusRequestInfo.openid);
            object.put("template_id", orderStatusRequestInfo.template_id);
            object.put("url",orderStatusRequestInfo.callurl);
            JSONObject array=new JSONObject();
            //frist
            JSONObject fristremark=new JSONObject();
            fristremark.put("value", orderStatusRequestInfo.frist);
            //"color":"#173177"
            fristremark.put("color", "#173177");
            array.put("first",fristremark);
            //keynote1 订单号
            JSONObject priceObject=new JSONObject();
            priceObject.put("value", orderStatusRequestInfo.orderid);
            array.put("keyword1",priceObject);
            //keynote2 订单状态
            JSONObject orderObject=new JSONObject();
            String orderstatuts=orderStatusRequestInfo.coverStatusString();
            orderObject.put("value",orderstatuts);
            array.put("keyword2",orderObject);
            //keynote3 时间状态
            JSONObject timeObject=new JSONObject();
            String time= TimeUtil.coverFormatTime(new Date());
            timeObject.put("value",time);
            array.put("keyword3",timeObject);
            //remark
            JSONObject remarkObject=new JSONObject();
            remarkObject.put("value", orderStatusRequestInfo.remark);
            array.put("remark",remarkObject);
            object.put("data", array);
            String requeString=object.toString();
            System.out.println("发送模版包体 =="+requeString);
            return requeString.getBytes("utf-8");
        } catch (Exception e) {
            // TODO: handle exception
            return null;
        }
    }

    @Override
    public void modifyUrl(RequestInfo info) {

    }
}
